//
//  OrderApi.m
//  danpin
//
//  Created by chuangjia on 8/12/2015.
//  Copyright © 2015 chuangjia. All rights reserved.
//

#import "OrderApi.h"

@implementation OrderApi
/*
 【收货地址列表】
 
 接口参数
 action = getShopAddressList
 
 返回值
 {'code'=>1, 'msg'=>'success','list'=>{}}
 */
+ (void)getShopAddressList:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=getShopAddressList";
    [self cancel];
    [self requestWithUrl:urls params:nil allowFetchCache:NO success:success failure:failure];
}
/*
 【添加收货地址】
 
 接口参数
 action = addShopAddress
 
 业务参数
 real_name	// 真实姓名
 id_card	// 订单标题
 id_card_front 	// 身份证正面照片
 id_card_behind	// 身份证反面照片
 province_id	// 省
 city_id	// 市
 town_id	// 区
 detail_address // 详细地址
 phone		// 手机号
 
 返回值
 {'code'=>1, 'msg'=>'success'}
 
 */
+ (void)addShopAddress:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=addShopAddress";
    [self cancel];
    [self requestWithUrl:urls params:params allowFetchCache:NO success:success failure:failure];
}
/*
 
 【修改收货地址】
 
 接口参数
 action = editShopAddress
 业务参数
 real_name	// 真实姓名
 id_card	// 订单标题
 id_card_front 	// 身份证正面照片
 id_card_behind	// 身份证反面照片
 province_id	// 省
 city_id	// 市
 town_id	// 区
 detail_address // 详细地址
 phone		// 手机号
 
 返回值
 {'code'=>1, 'msg'=>'success'}
 
 */
+ (void)editShopAddress:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=editShopAddress";
    [self requestWithUrl:urls params:params allowFetchCache:NO success:success failure:failure];
}
/*
 action = delShopAddress
 id
 */
+ (void)delShopAddressById:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=delShopAddress&id=%@";
    NSString *strul =[NSString stringWithFormat:urls,[params stringForKey:@"id"]];
    [self requestWithUrl:strul params:nil allowFetchCache:NO success:success failure:failure];
}
/*
 【设置默认收货地址】
 
 接口参数
 action = setDefaultShopAddress
 
 业务参数
 id		// 收货地址id
 
 返回值
 {'code'=>1, 'msg'=>'success'}
 
 */
+ (void)setDefaultShopAddress:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=setDefaultShopAddress&id=%@";
    NSString *strul =[NSString stringWithFormat:urls,[params stringForKey:@"id"]];
     [self requestWithUrl:strul params:nil allowFetchCache:NO success:success failure:failure];
}
/*
 【根据ID获取收货地址】
 
 接口参数
 action = getShopAddressById
 
 返回值
 {'code'=>1,'msg'=>'success','row'=>$row}
 
 */
+ (void)getShopAddressById:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=getShopAddressById&id=%@";
    NSString *strul =[NSString stringWithFormat:urls,[params stringForKey:@"id"]];
    [self requestWithUrl:strul params:nil allowFetchCache:NO success:success failure:failure];
}
/*
 【获取所有省市地址】
 接口参数 action = getPctAllData
 */
+ (void)getPctAllData:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=getPctAllData";
    [self requestWithUrl:urls params:nil allowFetchCache:YES success:success failure:failure];
}
/*
 【获取默认收货地址】
 
 接口参数
 action = getDefaultAddress
 
 返回值
 {'code'=>1,'msg'=>'success','row'=>$row}
 
 
 --------------------------------
 */
+ (void)getDefaultAddress:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=getDefaultAddress&type=%@";
    NSString *strul =[NSString stringWithFormat:urls,[params stringForKey:@"type"]];
    [self cancel];
     [self requestWithUrl:strul params:nil allowFetchCache:NO success:success failure:failure];
}
/*
 上传图片接口：
 http://www.danpin.com/api/uploadIdCard.php
 
 上传参数文件名 upfile
 */
+(void)uploadIdCard:(NSDictionary*)params images:(NSArray *)images success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure uploadProgress:(void(^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))progress
{
    
    [[ZApi SharedZApi] uploadImagesWithURL:@"http://api.danpin.com/uploadIdCard.php" paras:params images:images success:^(AFHTTPRequestOperation *operation, id resultObject) {
        success(operation,resultObject);
    } failure:^(NSError *requestErr) {
        failure(requestErr);
    } uploadProgress:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
        progress(bytesWritten,totalBytesWritten,totalBytesExpectedToWrite);
    }];
}


/*
 【添加订单】
 
 接口参数
 action = addShopOrder
 
 业务参数
 
 subject	// 订单标题
 body,		// 交易描述信息
 send_fee	// 国际运费
 total_fee	// 订单总价
 num		// 购买数量
 goods_info     // 商品信息都放在这里
 {
 good_fee	// 商品价格
 good_img	// 商品图片
 good_name	// 商品名称
 good_intro	// 商品简介
 goods_sn	// 商品编号
 .....		// 其他
 }
 
 返回值
 {'code'=>1, 'msg'=>'success','return_url'=>h5界面url}
 
 */
+ (void)addShopOrder:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=addShopOrder&type=%@";
    NSString *strul =[NSString stringWithFormat:urls,[params objectForKey:@"type"]];
    [self requestWithUrl:strul params:params allowFetchCache:NO success:success failure:failure];
}
/*
 --------------------------------
 
 【取消订单】
 接口参数 action = removeOrder
 业务参数 out_trade_no	//订单号
 
 返回json
 {
 "code": 1,
 "msg": "取消订单成功"
 }
 
 */
+ (void)removeOrder:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=removeOrder&out_trade_no=%@";
    NSString *strul =[NSString stringWithFormat:urls,[params objectForKey:@"out_trade_no"]];
    [self requestWithUrl:strul params:nil allowFetchCache:NO success:success failure:failure];
}
/*
 【订单确认签收】
 接口参数 action = signOrder
 业务参数 out_trade_no	//订单号
 
	返回json
	{
 "code": 1,
 "msg": "订单签收状态已确认"
	}
 */
+ (void)signOrder:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=signOrder&out_trade_no=%@";
    NSString *strul =[NSString stringWithFormat:urls,[params objectForKey:@"out_trade_no"]];
    [self requestWithUrl:strul params:nil allowFetchCache:NO success:success failure:failure];
}
/*
 【订单列表】
 
 接口参数
 action = getShopOrderList
 
 业务参数
 page	// 第几页
 status //状态
 返回值
 {'data'=>{}, 'end'=>'1'}
 
 ----------------------------------
 */
+ (void)getShopOrderList:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=getShopOrderList&status=%@&from=%@";
    NSString *strul =[NSString stringWithFormat:urls,[params objectForKey:@"status"],[params objectForKey:@"from"]];
    [self requestWithUrl:strul params:nil allowFetchCache:NO success:success failure:failure];
}
/*
 【根据ID获取订单】
 
 接口参数 action = getShopOrderById
 
 业务参数
 id	// 订单号
 
 返回值
 die(json_encode(array('code'=>1,'msg'=>'success','row'=>$row)));
 */
+ (void)getShopOrderById:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=getShopOrderById&id=%@";
    NSString *strul =[NSString stringWithFormat:urls,[params objectForKey:@"id"]];
    [self requestWithUrl:strul params:nil allowFetchCache:NO success:success failure:failure];
}
/*
 【支付成功后-同步通知】
 接口参数 action = alipayReturnUrl
 业务参数 return_data  // json 所有支付宝数据参数
 {'code'=>1, 'msg'=>'success'}
 */
+ (void)alipayReturnUrl:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=alipayReturnUrl";
    [self requestWithUrl:urls params:params allowFetchCache:NO success:success failure:failure];
}
/*【用户抵扣积分】
 【获取用户积分】
 
 接口参数 action = getUserScore
 
 {'code'=>1,'status'=>'success','score'=>123}
 */
+ (void)getUserScore:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=getUserScore&type=%@";
    NSString *strul =[NSString stringWithFormat:urls,[params objectForKey:@"type"]];
    [self requestWithUrl:strul params:params allowFetchCache:NO success:success failure:failure];
}
/*【获取用户余额】
 接口参数 action = getUserBalance
 业务参数 无
 
	返回json
	{
 "code": 1,
 "balance" : 10,
 "msg": "user balance"
	}
 */
+ (void)getUserBalance:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=getUserBalance";
    [self requestWithUrl:urls params:params allowFetchCache:NO success:success failure:failure];
}
/*余额抵税
 action = balanceTariff
 业务参数 out_trade_no
 */
+ (void)balanceTariff:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=balanceTariff&out_trade_no=%@";
    NSString *strul =[NSString stringWithFormat:urls,[params objectForKey:@"out_trade_no"]];
    [self requestWithUrl:strul params:params allowFetchCache:NO success:success failure:failure];
}
/*
 【用户留言】
 接口参数 action = addGuestMessage
 
 业务参数 out_trade_no  // 订单号
	question     //用户描述的问题
 
 {'code':1, 'msg':'感谢回馈，我们小编会联系您'}
 
 */
+ (void)addGuestMessage:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=addGuestMessage";
    [self requestWithUrl:urls params:params allowFetchCache:NO success:success failure:failure];
    
}
/*
 【用户余额日志】
 接口参数 action = getShopBalanceList
 
 业务参数 from
 psize
 
 直接返回列表
 
 --------------------------------
 */
+ (void)getShopBalanceList:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=getShopBalanceList&from=%@";
    NSString *strul =[NSString stringWithFormat:urls,[params objectForKey:@"from"]];
    [self requestWithUrl:strul params:nil allowFetchCache:NO success:success failure:failure];
}
/*
 --------------------------------
 
 【申请提现】
 接口参数 action = applyForCash
 
 业务参数 fee		//提现金额
 phone		//手机号
 real_name	//真实姓名
 alipay_account	//支付宝账号
 
 
 返回json
 die(json_encode(array('code'=>1,'msg'=>'暂时不能申请提现')));
 --------------------------------
 */
+ (void)applyForCash:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=applyForCash";
    [self requestWithUrl:urls params:params allowFetchCache:NO success:success failure:failure];
}
/*
 --------------------------------
 
 【抵扣金额是否可用】
 接口参数 action = isCutFeeAllowed
 
 业务参数 dk_type	//抵扣类型  1积分、2用户余额
 dk_fee	//抵扣金额
 price		//原商品价格（抵扣前）
 out_trade_no	//订单号
 
 
 返回json
 'code'=> 1,
 'price' => $price,	//减去抵扣金额的支付价格
 'out_trade_no'=>$out_trade_no, //订单号
 'encryption' => $encryption //私密串
 
 客户端需要的私密Keys：chrdwHDHXT12345ssdlh
 加密方式  md5(
 $out_trade_no		//订单号
 $_SESSION['user_id'].	//用户登陆uid
 $price.			//$price原商品价
 $Keys			//私密Keys（不可向外泄露）
 $session['user_score']	//用户积分
 $session['user_balance']//用户余额
 date('YmdH')		//年月日时2015110711
 );
 
 --------------------------------
 */
+ (void)isCutFeeAllowed:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=isCutFeeAllowed";
    [self requestWithUrl:urls params:params allowFetchCache:NO success:success failure:failure];
}
/*
-------------------------
【单品优惠码】

接口参数
action = getPublicCode

业务参数
order_dp_code

返回值 json

{"code":"1","msg":"优惠券抵扣5元","code_fee":"5.00"}
 */
+ (void)getDiscountCode:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    NSString *urls =@"/shop.php?action=getPublicCode";
    [self requestWithUrl:urls params:params allowFetchCache:NO success:success failure:failure];
}
/*
 todaywidget
 */
+(void)getTodayGood:(NSDictionary*)params success:(void(^)(AFHTTPRequestOperation* operation, id result))success failure:(void(^)(NSError* error))failure
{
    
    NSString *urls =@"/shop.php?action=getTodayGoods";
    [self requestWithUrl:urls params:params allowFetchCache:NO success:success failure:failure];
}
@end
